home *** CD-ROM | disk | FTP | other *** search
- TURBO PASCAL JOYSTICK ROUTINES
-
- Copyright (c) 1989, 1990 David B. Howorth
-
- Version 3.0b
-
-
- A. The files.
-
- This file is distributed with two others. The three files are:
-
- JOYSTICK.DOC This file.
- JOYSTICK.PAS The key file, which must be compiled to create JOYSTICK.TPU.
- JOYDEMO.PAS A demonstration of the routines in JOYSTICK.TPU.
-
- B. What to do if you're in a hurry.
-
- Compile JOYSTICK.PAS to disk. Then compile JOYDEMO.PAS in memory or
- to disk and run it. Fool around. Then read this file and the comments in the
- other files to figure out what you've been doing.
-
- C. What's in it for me.
-
- Although it would be nice to have a nickel for every time NYET and ARGH
- have been played, I've never charged anything for NYET and did not distribute
- ARGH as shareware until version 4.0. In keeping with those loose business
- practices, I encourage you to give away copies of these files, as long as you
- distribute all three files together. I do, however, prohibit you from selling
- them: I may not be smart enough to make money from my efforts, but I'm not
- going to let someone else do it without me.
-
- Beginning with this release, however, I am imposing a condition for
- the use of compiled versions of these routines in programs that are
- distributed, whether commercially or noncommercially. That condition is
- simply that you mail me a disk (either size) with one copy of the executable
- program and include any documentation; and, if you distribute your program as
- shareware, treat me as registered. What lies behind this condition is not
- a desire to amass a huge software library, but simply curiosity--like
- releasing a helium baloon with a return postcard inside.
-
- D. What's new in this version.
-
- A lot. When I wrote version 1 of these routines a few years ago, you
- had to program pretty close to the metal to do anything with the joystick.
- Since then the ROM BIOS has been extended to include a service that reports on
- the joystick. Of course, there are still loads of PCs and XTs out there with
- older ROM BIOS, which doesn't know a joystick from Shelley's Ode to the West
- Wind. This version tries to have it both ways, and I think it succeeds. The
- key routines are private to the unit and are written in two versions, one set
- of routines using the new BIOS services and another independent of them.
- Procedure variables are declared so that the initialization part of the unit
- can assign the correct procedures to the variables, after checking the date of
- the ROM BIOS (see the private function NewBIOS). The public routines simply
- incorporate the appropriate procedure variables.
-
- One note about the initialization process. NewBIOS checks the ASCII
- date characters at $F000:$FFFB and $FFFC. According to Peter Norton's New
- Programmer's Guide, however, not all IBM compatibles keep their ROM BIOS date
- there. The way I have written NewBIOS, if there is no date here, JOYSTICK.TPU
- will assume that there is no BIOS support for the joystick and will use my
- "old" (though improved) routines. That is obviously the best way to ensure
- portability. If your compatible does not have its ROM BIOS date at the IBM
- location and you know that its BIOS supports the joystick, you can change the
- initialization section of JOYSTICK.PAS so that the procedure variables are
- always set equal to the new routines. I don't think there would be much
- advantage in doing that, however, and it will certainly limit the
- portabilitity of your program.
-
- This release has a slightly rewritten version of OldReadJoy, the
- fundamental procedure of the "old" routines. In the three years or so that my
- original routine was available, I received only two complaints from users who
- said they had problems with ReadJoy, as OldReadJoy used to be called, but I
- was stunned to learn by accident a few weeks ago that the procedure did not
- work on my own machine unless two joysticks were installed. As the routine is
- now written, it reads only one joystick at a time; there are separate public
- procedures for each joystick. In response to requests, I have also added
- comments to OldReadJoy's inline code.
-
- E. How the non-BIOS routines work.
-
- The IBM joystick port is located at hex 201. All the information
- about both joysticks can be read in the byte at that port. Each bit reports
- on a specific thing, namely:
-
- Bit Reports on
-
- 0 Joystick A X-Axis Coordinate
- 1 Joystick A Y-Axis Coordinate
- 2 Joystick B X-Axis Coordinate
- 3 Joystick B Y-Axis Coordinate
- 4 Joystick A Button #1 (usually the top button)
- 5 Joystick A Button #2
- 6 Joystick B Button #1
- 7 Joystick B Button #2
-
- To read the status of a button, you simply read the relevant bit. If
- the bit is 1, the button is not pressed; if it is 0, the button is pressed.
- Aside from the fact that this relationship seems counterintuitive, reading the
- buttons is a simple task, easily accomplished with the Turbo Pascal port array
- and a little bit masking.
-
- The stick itself is a different story. How is it possible to get
- enough information from one bit? The answer is that you get it by repeated
- reads of the relevant bit. The process works like this: when you output
- something--anything--to port 201, the lower four bits are all set to 1
- automatically. (I think of this as "nudging" the port.) The length of time
- it takes each bit to return to 0 depends on the position of the stick. For
- example, if Joystick A is all the way to the left, Bit 0 will bounce back to 0
- immediately after a nudge. If it is all the way to the right, it will take
- longer to return to 0. If it is centered, it will take about half as long to
- return to 0 as it does when it is all the way to the right.
-
- You can use the Turbo Pascal port array in a loop to make successive
- reads of port 201, but that's too slow to be very accurate. The inline code
- incorporated in OldReadJoy is fast and does the job.
-
- F. Loose ends.
-
- 1. The buttons. I am a bit concerned that there may be joysticks out
- there whose buttons work counter to the usual way. If my routines show that
- your buttons are out when they are in and vice versa, you can work around
- that, but you shouldn't have to. I can easily rewrite JOYSTICK.PAS so that it
- can test the button condition at start-up and assume that that is the out
- position. I did not want to do that since it might turn out to be pointless
- overhead, but if it needs to be done, let me know and I will fix it in the
- next release.
-
- 2. Function JoystickPresent. This function works by reading the
- equipment-list word in low memory. According to Peter Norton's Programmer's
- Guide, this information may sometimes be inaccurate. It may be preferable
- simply to ask the user whether he has (or wants to use) a joystick.
-
- David Howorth
-
- 01960 SW Palatine Hill Road
- Portland, Oregon 97219
-
- CIS User ID: 71600,521
- GEnie Addr: D.HOWORTH
-
- October 22, 1990
- ----------------end-of-author's-documentation---------------
-
- Software Library Information:
-
- This disk copy provided as a service of
-
- Public (software) Library
-
- We are not the authors of this program, nor are we associated
- with the author in any way other than as a distributor of the
- program in accordance with the author's terms of distribution.
-
- Please direct shareware payments and specific questions about
- this program to the author of the program, whose name appears
- elsewhere in this documentation. If you have trouble getting
- in touch with the author, we will do whatever we can to help
- you with your questions. All programs have been tested and do
- run. To report problems, please use the form that is in the
- file PROBLEM.DOC on many of our disks or in other written for-
- mat with screen printouts, if possible. PsL cannot debug pro-
- programs over the telephone, though we can answer questions.
-
- Disks in the PsL are updated monthly, so if you did not get
- this disk directly from the PsL, you should be aware that the
- files in this set may no longer be the current versions. Also,
- if you got this disk from another vendor and are having prob-
- lems, be aware that some files may have become corrupted or
- lost by that vendor. Get a current, working disk from PsL.
-
- For a copy of the latest monthly software library newsletter
- and a list of the 2,000+ disks in the library, call or write
-
- Public (software) Library
- P.O.Box 35705 - F
- Houston, TX 77235-5705
-
- Orders only:
- 1-800-2424-PSL
- MC/Visa/AmEx/Discover
-
- Outside of U.S. or in Texas
- or for general information,
- Call 1-713-524-6394
-
- PsL also has an outstanding
- catalog for the Macintosh.
-
-